<?php 

function option($items, $parent_id, $cat_id, $level=0) {
    foreach ($items as $item) {
        if ($item['id']==$cat_id) continue;
        
        $selected = ($item['id']==$parent_id) ? 'selected' : '';
        echo '<option value="'.$item['id'].'" '.$selected.'>';
        echo str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', $level).$item['name'];
        if (isset($item['children']) && is_array($item['children'])) {
            option($item['children'], $parent_id, $cat_id, $level+1);
        }
        echo '</option>';
    }
}
?>

<?= HTML::style('static/bootstrap-3.3.7/css/bootstrap-datepicker.css')?>

<form action="" method="post" class="form-horizontal ajax-submit" enctype="multipart/form-data">
	
	<div class="form-group">
		<label class="col-sm-1 control-label">项目名称</label>
		<div class="col-sm-6">
			<input class="form-control" type="text" name="project_name" value="<?= $info['project_name'] ?>" required >
		</div>
	</div>
	
	<div class="form-group">
		<label class="col-sm-1 control-label">作品类型</label>
		<div class="col-sm-6">
    		<select class="form-control" name="project_cid">
    		<option value="0"> -选择作品类型- </option>
    			<?php if(Arr::get($_GET, 'pid')):?>
    			<?php option($cat_tree, Arr::get($_GET, 'pid'), 0);?>
    			<?php else:?>
    			<?php option($cat_tree, $info['project_cid'], $info['id']);?>
    			<?php endif;?>	
            </select>
        </div>
	</div>
	
	<div class="form-group">
		<label class="col-sm-1 control-label">行业类型</label>
		<div class="col-sm-6">
    		<select class="form-control" name="profession_cid">
    		<option value="0"> -选择行业类型- </option>
    			<?php if(Arr::get($_GET, 'pid')):?>
    			<?php option($cat_tree2, Arr::get($_GET, 'pid'), 0);?>
    			<?php else:?>
    			<?php option($cat_tree2, $info['profession_cid'], $info['id']);?>
    			<?php endif;?>	
            </select>
        </div>
	</div>

<!--    <div class="form-group">-->
<!--        <label class="col-sm-1 control-label">封面图</label>-->
<!--        <div class="form-group ">-->
<!--            <div id="works_pic_con">-->
<!--            </div>-->
<!--            <div id="works_pic_btn" >-->
<!--                <img class="img-thumbnail" style="margin-left: 1%;" src="/static/img/default.png"/>-->
<!--            </div>-->
<!--        </div>-->
<!--    </div>-->
	

    <div class="form-group">
        <label for="address" class="col-sm-1 control-label"><i class="iconfont icon-dian color-blue"></i>拍摄地区</label>
        <div class="col-sm-10">
            <div class="form-group col-sm-2">
                <select class="form-control" id="province" name="province" required></select>
            </div>
            <div class="form-group col-sm-1"></div>

            <div class="form-group col-sm-2">
                <select class="form-control" id="city" name="city" required></select>
            </div>
            <div class="form-group col-sm-1"></div>
            <div class="form-group col-sm-2">
                <select class="form-control" id="area" name="area" required></select>
            </div>
            <!-- <input type="text" class="form-control " id="address"> -->
        </div>
    </div>
	<div class="form-group">
		<label class="col-sm-1 control-label">预算</label>
		<div class="col-sm-2">
			<input class="form-control" type="text" name="actual_budget" value="<?= $info['actual_budget'] ?>" required >
		</div>
	</div>
    <div class="form-group">
        <label class="col-sm-1 control-label">实拍天数</label>
        <div class="col-sm-2">
            <input class="form-control" type="text" name="video_time" value="<?= $info['video_time'] ?>" required autocomplete="off">
        </div>
    </div>
	
	<div class="form-group">
		<label class="col-sm-1 control-label">开始日期</label>
		<div class="col-sm-2">
			<input type="text" class='form-control selectData' id='startDate' name='project_begin' value="<?= date('Y-m-d',$info['project_begin']) ?>" required  > 
		</div>
	</div>
	
	
	<div class="form-group">
		<label class="col-sm-1 control-label">结束日期</label>
		<div class="col-sm-2">
			<input type="text" class='form-control selectData' id='startDate' name='project_end' value="<?= date('Y-m-d',$info['project_end']) ?>" required   >
		</div>
	</div>
	
	<div class="form-group">
		<label class="col-sm-1 control-label">出品商</label>
		<div class="col-sm-2">
			<input class="form-control" type="text" name="author" value="<?= $info["author"] ?>" required >

		</div>
	</div>

	<div class="form-group">
		<label class="col-sm-1 control-label">简介</label>
		<div class="col-sm-6">
			<input class="form-control" type="text" name="desc" value="<?= $info['desc'] ?>" required >

		</div>
	</div>







    <div class="form-group video_url">
	<?php if (!empty($info['video'])):?>
	<?php for ($n=0; $n<count($info['video']); $n++):?>
		<div class="col-sm-12 video">
    		<label class="col-sm-1 control-label">视频地址</label>
    		<div class="col-sm-6">
    			<input class="form-control" type="text" name="video" value="<?= $info['video'] ?>" required >
    		</div>
		</div>
	<?php endfor;?>
	<?php else:?>
		<div class="col-sm-12 video">
    		<label class="col-sm-1 control-label">选择视频</label>
            <select class="form-control" name="video" style="width:620px ">
                <option value="0"> -选择添加- </option>
                <?php foreach ($video as $item):?>
                    <option value="<?= $item['url']?>"> <?= $item['video_title']?></option>
                <?php endforeach;?>
            </select>
		</div>
	<?php endif;?>
	</div>
	
	<div class="form-group">
		<div class="col-sm-offset-1 col-sm-3">
			<button type="submit" class="btn btn-primary">提交</button>
		</div>
	</div>
	
	
</form>

<style>
div.mce-fullscreen {z-index: 9999;}
.mce-menubtn.mce-fixed-width span {width:auto}
</style>
<?= HTML::script('static/tinymce/tinymce.min.js')?>
<?= HTML::script('/static/js/jquery.city.js')?>

<script type="text/javascript">
tinyMCE.init({
	selector : 'textarea#editor',
	plugins: [
		  		"advlist autolink lists link image charmap print preview anchor",
		  		"searchreplace visualblocks code fullscreen imagetools upload",
		  		"insertdatetime media table contextmenu paste textcolor colorpicker emoticons",
		  		"codesample eqneditor"
		  	],
  	toolbar: "upload undo redo | fontselect fontsizeselect forecolor | bold italic | link image emoticons | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | fullscreen preview",
  	autosave_ask_before_unload: false,
  	convert_urls: false,
    force_br_newlines : true,
    force_p_newlines : false,
    forced_root_block : '', // Needed for 3.x
	height : 400,
	content_css: ['<?= URL::site('static/css/preview.css')?>'],
	language: 'zh_CN'
});
</script>


<style>
.up-item{float:left;width:160px;margin:5px;position:relative}
.up-item .close{position:absolute;right:3px;top:0;}
.up-item .img-thumbnail{width:160px;}
.up-item .progress{position:absolute;left:0;bottom:0;width:100%;height:8px;margin:0;display:none}
</style>
<?php include __DIR__ . '/../plupload.php';?>
<?= HTML::script('static/bootstrap-3.3.7/js/bootstrap-datepicker.js')?>
<script>

$(function() {
    init_address('province', 'city', 'area', '<?= $info['province'] ?>', '<?= $info['city'] ?>', '<?= $info['area'] ?>');
    //上传作品图片
    init_upload('works_pic_btn','works_pic_con','img');
});
</script>
<script>
$.fn.datepicker.dates['cn'] = {   //切换为中文显示  
        days: ["周日", "周一", "周二", "周三", "周四", "周五", "周六", "周日"],  
                daysShort: ["日", "一", "二", "三", "四", "五", "六", "七"],  
                daysMin: ["日", "一", "二", "三", "四", "五", "六", "七"],  
                months: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],  
                monthsShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],  
                today: "今天",  
                clear: "清除"  
    };  
  
     $('.selectData').datepicker({  
        autoclose: true, //自动关闭  
        beforeShowDay: $.noop,    //在显示日期之前调用的函数  
        calendarWeeks: false,     //是否显示今年是第几周  
        clearBtn: false,          //显示清除按钮  
        daysOfWeekDisabled: [],   //星期几不可选  
        endDate: Infinity,        //日历结束日期  
        forceParse: true,         //是否强制转换不符合格式的字符串  
        format: 'yyyy-mm-dd',     //日期格式  
        keyboardNavigation: true, //是否显示箭头导航  
        language: 'cn',           //语言  
        minViewMode: 0,  
        orientation: "bottom",      //方向  
        rtl: false,  
        startDate: -Infinity,     //日历开始日期  
        startView: 0,             //开始显示  
        todayBtn: false,          //今天按钮  
        todayHighlight: true,    //今天高亮  
        weekStart: 0              //星期几是开始  
    }); 
</script>